#ifndef __BSP_LCD_H
#define __BSP_LCD_H

#include "main.h"

#define LCD_WIDTH 320
#define LCD_HEIGHT 480
#define DMA_PER_SIZE 8192                           //经测试，每次传输8192字节，速度最快且显示不会出错
#define LCD_TOTAL_SIZE (LCD_WIDTH * LCD_HEIGHT)
#define LCD_TOTAL_BUF_SIZE (LCD_TOTAL_SIZE * sizeof(uint16_t))
#define DMA_LOOP_NUM (LCD_TOTAL_BUF_SIZE / DMA_PER_SIZE)
#define DMA_LOOP_NUM_LEFT (LCD_TOTAL_BUF_SIZE % DMA_PER_SIZE)

#define LCD_DIR 1   //0-竖屏 1-横屏

#define RGB 0x00
#define BGR 0x08
#define COLORORDER BGR


#define LCD_CS PAout(4)     //SPI片选
#define LCD_RST PCout(5)    //LCD复位
#define LCD_RS PCout(4)     //LCD寄存器选择 1-数据 0-命令

#define LCD_SETX_CMD 0x2A
#define LCD_SETY_CMD 0x2B
#define LCD_WR_CMD 0x2C
#define LCD_DIR_REG 0x36


#define L2R_U2D  0
#define L2R_D2U  1
#define R2L_U2D  2
#define R2L_D2U  3

#define U2D_L2R  4
#define U2D_R2L  5
#define D2U_L2R  6
#define D2U_R2L  7


void bsp_lcd_init(void);
void bsp_lcd_clear(uint16_t u16Color);
void bsp_lcd_clear_fast(uint16_t u16Color);

void bsp_lcd_fill(              uint16_t u16StartX,
                                uint16_t u16StartY,
                                uint16_t u16EndX,
                                uint16_t u16EndY,
                                uint16_t u16Color);

void bsp_lcd_fill_block(        uint16_t u16StartX,
                                uint16_t u16StartY, 
                                uint16_t u16EndX,
                                uint16_t u16EndY,
                                uint16_t *u16Color);

void bsp_lcd_fill_block_fast (  uint16_t u16StartX,
                                uint16_t u16StartY, 
                                uint16_t u16EndX,
                                uint16_t u16EndY,
                                uint16_t *u16Color);

void LCD_ShowChar(              uint16_t u16XPos, 
                                uint16_t u16YPos, 
                                int8_t i8Chr, 
                                uint8_t u8Size, 
                                uint8_t u8Mode, 
                                uint16_t u16Color);   

void LCD_ShowString(            uint16_t x,
                                uint16_t y,
                                uint16_t width,
                                uint16_t height,
                                uint8_t size,
                                uint8_t *p,
                                uint16_t color);

void bsp_lcd_showChinese(   uint16_t u16XPos,
                            uint16_t u16YPos,
                            uint16_t u16gb2312code,
                            uint16_t u16Color,
                            uint16_t u16BgColor);

void bsp_lcd_showChineseStr(    uint16_t u16XPos,
                                uint16_t u16YPos,
                                uint16_t u16Color,
                                uint16_t u16BgColor);

void bsp_lcd_showTime(          uint16_t u16XPos,
                                uint16_t u16YPos,
                                uint16_t u16Color);
#endif /* __BSP_LCD_H */
